<%-- 
    Document   : SelectedFile
    Created on : Jan 19, 2015, 8:34:16 PM
    Author     : user
--%>

<%@page import="java.io.BufferedReader"%>
<%@page import="java.io.FileReader"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="newpackage.ConnectionFactory"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.io.FileNotFoundException"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body background="image.jpg">
         <h1> ENSURING PRIVACY AND DATA FRESHNESS OF SHARED DATA IN CLOUD </h1>
        
 
        <textarea style="width: 1091px; height: 339px;" id="file_content" name="file_content" >
          <%
          try
          {
              
          if((request.getParameter("selected_file")!=null)&&(request.getParameter("key")!=null))
           
          {
              String key=request.getParameter("key");
            //  if(!key.equalsIgnoreCase(""))
            //  {
              String file_name=request.getParameter("selected_file");
              if(file_name.contains("read"))
                                   {
                file_name=file_name.replaceAll("read", "main");
              }
              
              
               else if(file_name.contains("update"))
                                   {
                   file_name=file_name.replaceAll("update", "main");
              }
              
              
              String query="SELECT * from file_details where filename='"+file_name+"' and secret_key='"+key+"'";
              Connection con=ConnectionFactory.getConnection();
              Statement st=con.createStatement();
           ResultSet rs1=st.executeQuery(query);
           if(rs1.next())
                             {
              
              String fileName=request.getParameter("file_name");
              BufferedReader br=new BufferedReader(new FileReader(fileName)) ;  
       String s;
while((s=br.readLine())!=null)          
       {
    out.println(s);
       }
          }
           else
           {
        out.print("Secretkey is wrong");       
           }
      //  }
                       }
          }
          catch(FileNotFoundException e)
       {
      out.println("File Not Found");
          }
          %>

        </textarea>
      <a href="Login.jsp">LogOut</a>
    </body>
</html>
